#include "stdio.h"

void FilterGameEx(char * buff,DWORD len,Character * character)
{
	int subLen=strlen(character->name);
	int len1=character->shangshen[0];
	int len2=character->beibu[0];
	int len3=character->yanjing[0];
	int len4=character->toufa[0];

	if(len1==0&&len2==0&&len3==0&&len4==0)
	{
		return;
	}
	int pos=-1;
	for(int i=0;i<len;i++)
	{
		if(memcmp(character->name,buff+i,subLen)==0)
		{
			pos=i;
			break;
		}
	}
	if(pos!=-1)
	{
		::OutputDebugString("name found!");
		if(len1!=0 && pos+118<len)
		{
			TCHAR info[100];
			wsprintf(info,"beidu value, %d %d",buff[pos+117],buff[pos+118]);
			::OutputDebugString(info);
			if(buff[pos+118]==-92)
			{
				::OutputDebugString("shangshen replace!");
				buff[pos+117]=character->shangshen[0];
				buff[pos+118]=character->shangshen[1];
			}
		}
		if(len2!=0 && pos+102<len)
		{
			TCHAR info[100];
			wsprintf(info,"beidu value, %d %d",buff[pos+101],buff[pos+102]);
			::OutputDebugString(info);
			if(buff[pos+102]==-96)
			{
				::OutputDebugString("beibu replace!");
				buff[pos+101]=character->beibu[0];
				buff[pos+102]=character->beibu[1];
			}
		}
		if(len3!=0 && pos+70<len)
		{
			if(buff[pos+70]==70)
			{
				::OutputDebugString("yanjing replace!");
				buff[pos+69]=character->yanjing[0];
				buff[pos+70]=character->yanjing[1];
			}
		}
		if(len4!=0 && pos+62<len)
		{
			if(buff[pos+62]==66)
			{
				::OutputDebugString("toufa replace!");
				buff[pos+61]=character->toufa[0];
				buff[pos+62]=character->toufa[1];
			}
		}
	}
}

void FilterGame(char* buff,LPDWORD lpNumberOfBytesRecvd,PGameFilter filter)
{
	for(int i=0;i<filter->roleCount;i++)
	{
		FilterGameEx(buff,*lpNumberOfBytesRecvd,&filter->character[i]);
	}
}

